﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.Admin
{
    public partial class SetWebSite : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["adminName"] != null)
                {
                    lcmyjobs.BLL.admin_type at = new BLL.admin_type();
                    DropDownList1.DataSource = at.GetAllList().Tables[0];
                    DropDownList1.DataTextField = "atname";
                    DropDownList1.DataValueField = "atid";
                    DropDownList1.DataBind();
                    showme();
                }
                else
                {
                    Maticsoft.Common.MessageBox.ResponseScript(this, "alert('请先登陆！');top.location.href='adminlogin2.aspx'");
                }



            }

        }

        private void showme()
        {
            try
            {
                string ids = myPublic.GetConfig("webid");
                if (ids != "")
                    DropDownList1.SelectedValue = ids;
                txtname.Text = myPublic.GetConfig("webname");
                txtadd.Text = myPublic.GetConfig("sendEmailAdd");
                txtpas.Text = myPublic.GetConfig("sendEmailPwd");
                txtserver.Text = myPublic.GetConfig("emailHost");
                txtkeyword.Text = myPublic.GetConfig("keywords");
                txtdescript.Text = myPublic.GetConfig("description");
            }
            catch (Exception ex)
            {

                Maticsoft.Common.MessageBox.Show(this, ex.Message);
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                myPublic.Modify("webid", DropDownList1.SelectedValue);
                myPublic.Modify("webname", txtname.Text);
                myPublic.Modify("sendEmailAdd", txtadd.Text);
                myPublic.Modify("sendEmailPwd", txtpas.Text);
                myPublic.Modify("keywords", txtkeyword.Text);
                myPublic.Modify("description", txtdescript.Text);
                reloadApp();
                Maticsoft.Common.MessageBox.Show(this, "保存成功！");
            }
            catch (Exception ex)
            {

                Maticsoft.Common.MessageBox.Show(this, ex.Message);
            }


        }

        private void reloadApp()
        {
            Application.Lock();
            Application["webid"] = myPublic.GetConfig("webid");
            Application["webname"] = myPublic.GetConfig("webname");
            Application["sendEmailAdd"] = myPublic.GetConfig("sendEmailAdd");
            Application["sendEmailPwd"] = myPublic.GetConfig("sendEmailPwd");
            Application["emailHost"] = myPublic.GetConfig("emailHost");
            Application["emailHostPort"] = myPublic.GetConfig("emailHostPort");
            Application["keywords"] = myPublic.GetConfig("keywords");
            Application["description"] = myPublic.GetConfig("description");
            Application.UnLock();
        }
    }
}